# SOAP Web Service Library
# for use with Robot Framework 
#
# Zens 2012
#

#import logging
#logging.basicConfig(level=logging.DEBUG)
#logging.getLogger('suds.client').setLevel(logging.DEBUG)

import base64

from suds.client import Client
from suds import WebFault
from suds.sudsobject import Object

# Here is a bug of suds, must use INFO level logs, otherwise will occur "AttributeError: 'NoneType' object has no attribute 'str'"
import logging
logging.getLogger().setLevel(logging.INFO)

#from suds.xsd.doctor import Import, ImportDoctor




class SOAPWSLibrary:
    """ This is a library primarily meant for testing the SOAP web service.
		It's using the SUDS web service client for Python (https://fedorahosted.org/suds/)
	"""
        
    def __init__(self, url):

        self.client = Client(url)
        
        # Force client to use provided url instead of the one published in WSDL
        self.client.set_options(location=url.rstrip('?wsdl'))
        

    #
    # Helper keywords
    #
    


    #
    # Keywords exposing webservice methods
    #


    def GetExchangeRateObject(self, channel, password, userName, fromCurrency, toCurrency):
        """ Invokes the WS method of GetExchangeRate
        """
        arg0 = self.client.factory.create('arg0')
        arg0.channel = channel
	arg0.password = password
	arg0.userName = userName
	arg0.fromCurrency = fromCurrency
	arg0.toCurrency = toCurrency

        response = self.client.service.getExchangeRate(channel, password, userName, fromCurrency, toCurrency)

        # Print the sent SOAP message to Robot Framework log
        print self.client.last_sent()

        print response
        return response



